package com.pro01.backend.controller;

import com.pro01.backend.dto.PromotionActiveDTO;
import com.pro01.backend.dto.UserPromotionRecordDTO;
import com.pro01.backend.pojo.PageResult;
import com.pro01.backend.pojo.Promotion2;
import com.pro01.backend.pojo.Result;
import com.pro01.backend.service.Promotion2Service;
import com.pro01.backend.utils.TokenUtil;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.Map;

@RestController
@RequestMapping("/torrents/promotions2")
public class Promotion2Controller {

    @Autowired
    private Promotion2Service promotion2Service;
    @GetMapping("/active")
    public Result<PageResult<PromotionActiveDTO>> getActivePromotions(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {

        PageResult<PromotionActiveDTO> result = promotion2Service.getActivePromotionsPaged(pageNum, pageSize);
        return Result.success(result);
    }

    @GetMapping("/my-promotions")
    public Result<PageResult<UserPromotionRecordDTO>> getMyPromotionRecords(
            HttpServletRequest request,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {

        Long userId = TokenUtil.getUserId(request);
        PageResult<UserPromotionRecordDTO> result = promotion2Service.getUserPromotionsPaged(userId, pageNum, pageSize);
        return Result.success(result);
    }


}

